﻿using System.Collections.Specialized;
using System.IO;

namespace MyWcfRestLib.Files
{
    class ChunkUploadParams : FileOpParams
    {
        public const string PathKey = "path";
        public const string UploadIdKey = "upload_id";

        public ChunkUploadParams(string basePath, NameValueCollection requestQueryParams, Stream requestBody = null)
            : base(basePath, requestQueryParams, requestBody)
        {
            // Fix path string
            WorkingPath = (string)QueryParams[PathKey];
            UploadID = (string)QueryParams[UploadIdKey];
            if (null != WorkingPath)
            {
                WorkingPath = WorkingPath.Trim(InvalidFileNameChars);
            }
        }

        public string WorkingPath { get; private set; }
        public string UploadID { get; private set; }

        public override bool IsValid
        {
            get { return UtilityFunctions.IsValidPathName(WorkingPath) && !string.IsNullOrWhiteSpace(UploadID); }
        }
    }
}
